const path = require('path')
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const dotenv = require('dotenv')
const config = require('./.config.js')

const env = process.env.mode || process.env.NODE_ENV
// const devFlag = env === 'development'

module.exports = {
  mode: 'none',
  devtool: 'source-map',
  entry: {
    app: config.entry
  },
  output: {
    path: path.resolve(__dirname, config.outPath),
    filename: path.posix.join(config.staticPath, 'js/[name].[chunkhash].js'),
    chunkFilename: path.posix.join(config.staticPath, 'js/[name].[chunkhash].js'),
    publicPath: config.publicPath
  },
  optimization: {
    minimize: false
  },
  module: {
    rules: [
      {
        test: /.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /.js$/,
        loader: 'babel-loader',
        exclude: [path.resolve(__dirname, 'node_modules')]

      },
      {
        test: /.(js|vue)$/,
        loader: 'eslint-loader',
        exclude: [path.resolve(__dirname, 'node_modules')],
        enforce: 'pre'
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/,
        loader: 'url-loader',
        options: {
          esModule: false,
          limit: 6 * 1024,
          name: path.posix.join(config.staticPath, 'media/[name].[contenthash:6].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)$/,
        loader: 'url-loader',
        options: {
          esModule: false,
          limit: 6 * 1024,
          name: path.posix.join(config.staticPath, 'font/[name].[contenthash:6].[ext]')
        }
      }
    ]
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      vue$: 'vue/dist/vue.esm.js',
      '@': path.join(__dirname, 'src')
    }
  },
  plugins: [
    new VueLoaderPlugin(),
    new webpack.DefinePlugin({
      BASE_URL: JSON.stringify(config.envConfig.BASE_URL),
      'process.env': JSON.stringify(config.envConfig)
    })
  ],
  externals: {
    vue: 'Vue',
    'vue-router': 'VueRouter',
    axios: 'axios',
    vuex: 'Vuex'
  }
}
